//
//  mm_picRecodeDataModel.m
//  HondaPro_2
//
//  Created by Eric on 13-7-2.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "mm_picRecodeDataModel.h"

@implementation mm_picRecodeDataModel

@synthesize arrForAllFaultyObj = _arrForAllFaultyObj;
@synthesize point = _point;
@synthesize idIndexStr = _idIndexStr;
@synthesize typeStr = _typeStr;
@synthesize numberStr = _numberStr;
@synthesize remarksStr = _remarksStr;
@synthesize imgView = _imgView;

@synthesize arrForAllCapturePic = _arrForAllCapturePic;

static mm_picRecodeDataModel *picRecodeDataModelIns = nil;

//singleton
+(mm_picRecodeDataModel *)sharedModelIns
{
    if (nil == picRecodeDataModelIns)
    {
        //初次分配空间
        picRecodeDataModelIns = [[mm_picRecodeDataModel alloc] init];
    }
    return picRecodeDataModelIns;
}

-(id)init
{
    if (self = [super init])
    {
        //init code
        self.arrForAllFaultyObj = [NSMutableArray array];
        self.arrForAllCapturePic = [NSMutableArray array];
    }
    return self;
}

//添加一个故障标记到数组末尾

/*
 调用这个方法之前的操作：
 （1）设置属性 坐标点、划痕图标的名称、故障标记对象、数量、备注信息
 该方法中要完成的操作
 （1）根据（1）的设置确定 编号 和 类型
 （2）将以上属性整理成数组obj 存入 大数组（self.arrForAllFaultyObj）中
 */

-(void)addOneFaultyObjToArr
{
    self.idIndexStr = [self returnTheIdIndexStrBaseOnImgName:self.imgname];
    self.typeStr = [self returnTheTypeStrBaseOnImgName:self.imgname];
    
    NSMutableDictionary *dicTmp = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"",@"ITEM_ID",
                            [NSValue valueWithCGPoint:self.point],@"point",
                            self.idIndexStr,@"idIndexStr",
                            self.typeStr,@"typeStr",
                            self.numberStr,@"numberStr",
                            self.remarksStr,@"remarksStr",
                            self.imgname,@"imgname",
                            self.imgView,@"imgView", nil];
    
    //添加图片列表
    MainMenuDataModel *modelIns = [MainMenuDataModel sharedMainMenuDataModel];
    if (nil != modelIns.arrOutCheckImageNameListTmp)
    {
        [dicTmp setObject:modelIns.arrOutCheckImageNameListTmp forKey:MM_OUT_CHECK_IMAGE_NAME_LIST_KEY_STR_];
    }
    
    [self.arrForAllFaultyObj addObject:dicTmp];
}

#pragma mark - 根据 标记名称 返回 类型

-(NSString *)returnTheTypeStrBaseOnImgName:(NSString *)imgNameXingCan
{
    if ([imgNameXingCan isEqualToString:@"A.png"])
    {
        self.typeStr = @"凹痕";
    }
    else if ([imgNameXingCan isEqualToString:@"D.png"])
    {
        self.typeStr = @"掉漆";
    }
    else if ([imgNameXingCan isEqualToString:@"h.png"])
    {
        self.typeStr = @"划痕";
    }
    else if ([imgNameXingCan isEqualToString:@"L.png"])
    {
        self.typeStr = @"裂纹";
    }
    else if ([imgNameXingCan isEqualToString:@"P.png"])
    {
        self.typeStr = @"破损";
    }
    else if ([imgNameXingCan isEqualToString:@"X.png"])
    {
        self.typeStr = @"锈蚀";
    }
    
    return self.typeStr;
}

#pragma mark - 根据标记名称 返回 编号

/*
 返回编号的操作是：
 （1）遍历存有标记对象的数组，统计拥有对象 imgNameXingCan 的对象个数,
 （2）根据标记名称以及已有标记个数，确定新标记的编号
 */

-(NSString *)returnTheIdIndexStrBaseOnImgName:(NSString *)imgNameXingCan
{
    //确定标记的最大个数
    NSInteger nCount = 0;
    for (int i = 0; i<[self.arrForAllFaultyObj count]; i++)
    {
        NSDictionary *dicTmp = [self.arrForAllFaultyObj objectAtIndex:i];
        NSString *strTmp = [dicTmp objectForKey:@"imgname"];
        if ([strTmp isEqualToString:imgNameXingCan])
        {
            //取出当前的标记编号与nCount，进行大小比较，nCount最终保存最大值
            NSInteger nIdStrNumber = (NSInteger)[[[dicTmp objectForKey:@"idIndexStr"] substringFromIndex:1] integerValue];
            
            nCount = nCount >= nIdStrNumber ? nCount : nIdStrNumber;
        }
    }
    
    //确定新标记的编号
    if ([imgNameXingCan isEqualToString:@"A.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"A%i",nCount+1];
    }
    else if ([imgNameXingCan isEqualToString:@"D.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"D%i",nCount+1];
    }
    else if ([imgNameXingCan isEqualToString:@"h.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"H%i",nCount+1];
    }
    else if ([imgNameXingCan isEqualToString:@"L.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"L%i",nCount+1];
    }
    else if ([imgNameXingCan isEqualToString:@"P.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"P%i",nCount+1];
    }
    else if ([imgNameXingCan isEqualToString:@"X.png"])
    {
        self.idIndexStr = [NSString stringWithFormat:@"X%i",nCount+1];
    }
    
    return self.idIndexStr;
}

//根据标记编号 返回 标记名称
-(NSString *)returnTheImageNameStrBaseOnIdIndex:(NSString *)idIndexXingCan
{
    if ([idIndexXingCan rangeOfString:@"A"].length == [@"A" length])
    {
        self.imgname = @"A.png";
    }
    else if ([idIndexXingCan rangeOfString:@"D"].length == [@"D" length])
    {
        self.imgname = @"D.png";
    }
    else if ([idIndexXingCan rangeOfString:@"H"].length == [@"H" length])
    {
        self.imgname = @"h.png";
    }
    else if ([idIndexXingCan rangeOfString:@"L"].length == [@"L" length])
    {
        self.imgname = @"L.png";
    }
    else if ([idIndexXingCan rangeOfString:@"P"].length == [@"P" length])
    {
        self.imgname = @"P.png";
    }
    else if ([idIndexXingCan rangeOfString:@"X"].length == [@"X" length])
    {
        self.imgname = @"X.png";
    }
    
    return self.imgname;
}

#pragma mark - 数组懒加载
-(NSMutableArray *)arrForNewImage{
    if (_arrForNewImage == nil) {
        _arrForNewImage = [NSMutableArray array];
    }
    return _arrForNewImage;
}

-(NSMutableArray *)arrForDeletedImages{
    if (_arrForDeletedImages == nil) {
        _arrForDeletedImages = [NSMutableArray array];
    }
    return _arrForDeletedImages;
}

-(NSMutableArray *)arrForAllCapturePic{
    if (_arrForAllCapturePic == nil) {
        _arrForAllCapturePic = [NSMutableArray array];
    }
    return _arrForAllCapturePic;
}

@end
